package com.lg.concurrent.interrupt;


/**
 *  interrupt      不管原来什么 修改中断标志位为 true  无返回值
 *
 *  interrupted    不管原有状态是什么，修改 “当前线程” 标志位为false  返回修改前标志位状态
 *  isInterrupted  不清原有状态是什么  返回线程标志位
 *
 */
public class InterruptThread {

    static class InterruptT extends  Thread{
        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                System.out.println("interrupt run: "+i);
            }

            System.out.println("interrupt run this.isInterrupted(): "+this.isInterrupted());
            System.out.println("interrupt run this.isInterrupted(): "+this.isInterrupted());
            System.out.println("interrupt run this.interrupted(): "+this.interrupted());
            System.out.println("interrupt run this.interrupted(): "+this.interrupted());

        }
    }

    public static void main(String[] args) {

        /**
        *  interrupted  是否是中断状态  清除原有状态(不管原有状态是什么),改为false
        *  isInterrupted  是否是中断状态  不清原有除状态
        *
        */
//        InterruptT interruptT = new InterruptT();
//        interruptT.start();
//        interruptT.interrupt();

        /**
         *   interrupted  测试当前线程
         *
         *   interrupted 是一个静态方法 里面调用的是当前线程 currentThread().isInterrupted(true);
         */
        Thread.currentThread().interrupt();
        System.out.println("main is "+Thread.currentThread().isInterrupted());
        InterruptT interruptT = new InterruptT();
        System.out.println(interruptT.interrupted());
        System.out.println(interruptT.interrupted());
        System.out.println("main is "+Thread.currentThread().isInterrupted());




    }
}
